<%@ page import="com.bafa.objects.season.Season" %>
<%@ page import="com.bafa.objects.season.Division" %>
<%@ page import="com.bafa.objects.team.Team" %>
<%@ page import="com.bafa.objects.team.TeamSeasonStats" %>
<%@ page import="com.bafa.objects.team.TeamStats" %>
<%@ page import="com.bafa.objects.player.*" %>
<%@ page import="com.bafa.objects.*" %>
<%@ page import="com.bafa.middle.*" %>
<%@ page import="com.bafa.front.presentationbeans.*" %>
<%@ page import="java.util.*" %>
<% Report report = (Report)request.getAttribute("REPORT");   

%>
<% PlayerListBean players = (PlayerListBean)request.getAttribute("PLAYERS"); %>

<% MatchBean match = (MatchBean)request.getAttribute("MATCH");   %>
<% TeamBean team = (TeamBean)session.getAttribute("LOGGEDONTEAM"); 
%>
<% SeasonBean season = (SeasonBean)session.getAttribute("THISSEASON");   
if(season==null){season = (SeasonBean)request.getAttribute("CURRENTSEASON");}  %>
<link href="styles_5.css" rel="stylesheet" type="text/css" />
<link href="stats.css" rel="stylesheet" type="text/css">
<script  src="script/niftycube.js" type="text/javascript" ></script>
	<script>
	NiftyLoad=function(){
	     

Nifty("ul#results h3","top");
Nifty("ul#results div","bottom same-height");
}




function deletescorer(name){
	location.href='deletescorer.bafa?scorer='+name+'&matchId=<%=match.getID()%>';
	
}

var addedscorers = new Array();


var existingscorers = new Array();
<%if(players.players()!=null){
for(int i=0;i<players.players().length;i++){%>
existingscorers[<%=i%>] = "<%=players.players()[i].getName()%>";
<%}%>

<%}%>

var i = <%if(team.getId()==match.getTeamA()){%><%=match.getScorersA().players().length%><%}else{%><%=match.getScorersB().players().length%><%}%>;
var x = 0;

var team =  <%if(team.getId()==match.getTeamA()){%>'A'<%}else{%>'B'<%}%>;


function confirmScorer(name,goals){
var text = "goals";
	if(goals<2)
		text="goal";

	var innerhtml = document.getElementById('existingscorertable').innerHTML+'<b><input type="hidden" name="scorer'+team+''+i+'" value="'+name+'"/>'+name+' </b><b><input type="hidden" name="scoredgoals'+team+''+i+'" value="'+goals+'" /> - '+goals+' '+ text+'</b><br/>';
	document.getElementById('existingscorertable').innerHTML = innerhtml;
	
i++;
x=x+20;
}


</script>
<script type='text/javascript' src='dwr/interface/JDate.js'></script>
 <script type='text/javascript' src='dwr/interface/ajax.js'></script>
  <script type='text/javascript' src='dwr/engine.js'></script>
  <script type='text/javascript' src='dwr/util.js'></script>


 <script>
 
 function checkScore(){
 var goalsA = dwr.util.getValue("checkGoalsA");
 var goalsB = dwr.util.getValue("checkGoalsB");
 if(isNaN(goalsA) || isNaN(goalsB)){
 alert('Please check that your score is correct');
 }
 else{
 document.resultform.submit();
 }
 }
 var origtext;
  function autocomplete(e) {
  var code;
  if (e.keyCode) code = e.keyCode;
 	else if (e.which) code = e.which;
   if(code != 8 && code != 37 && code != 39){
     var name = dwr.util.getValue("addscorer");
     if(name!=""){
     origtext = name;
     ajax.getScorerName(name, function(data) {
     
     if(data!=""){
       dwr.util.setValue("addscorer", data);
       dwr.util.selectRange("addscorer",origtext.length,data.length);
       }
     });
     }
     }
}

function highlight(data){
var name = dwr.util.getValue("addscorer");
dwr.util.selectRange("addscorer",0,data.length);
}

</script>

<script language="JavaScript" type="text/javascript" src="wysiwyg.js"></script>
<style type="text/css">
	
ul#results,ul#results li{margin:0;padding:0;list-style:none}
	ul#results li{float:left;width:550;margin:0 10px 10px 0}
	ul#results h3{font: bold  Verdana,sans-serif;
	    text-transform:uppercase;margin:0px;padding: 5px 0 3px;text-align:center}
	ul#results p{margin:0;padding:5px 8px 15px}
	ul#results div{background:#FFFFFF}
	li#results div{border:2px solid #D2D2D2}
	
	
</style>
<form method="post" name="resultform" action="editscorers.bafa">
			<input type="hidden" name="teamA" value="<%=match.getTeamA()%>"/>
			<input type="hidden" name="matchId" value="<%=match.getID()%>"/>
			<input type="hidden" name="teamB" value="<%=match.getTeamB()%>"/>
			<input type="hidden" name="divisionId" value="<%=match.getDivisionId()%>"/>
			<input type="hidden" name="teamId" value="<%=team.getId()%>"/>
			<input type="hidden" name="seasonId" value="<%=season.getId()%>"/>
<ul id="results"><li id="results"><h3 class="avlh">Score</h3>
    <div class="sad">       <table class="bafatablelarge" width=100% border="0">
    <tr>
    <td ><%=match.getTeamAName()%> - <b><%=match.getGoalsA()%></font></b></td>
    <td ><%=match.getTeamBName()%> -  <b><%=match.getGoalsB()%></font></b></td>
    <td></td>
    </tr>
    
     <tr>
        <%if(team.getId()==match.getTeamA()){%>
        
          <td ><table width="250px"><%for(int u=0;u<match.getScorersA().players().length;u++){%><tr><td><b><input type="hidden" value="<%=match.getScorersA().players()[u].getName()%>" name="scorerA<%=u%>" /><%=match.getScorersA().players()[u].getName()%></b></td><td><b><input type="text" size="2" name="scoredgoalsA<%=u%>" value="<%=match.getScorersA().players()[u].getGoals()%>" maxlength=2/></td> <td>- Delete<input type="checkbox" onClick="javascript:deletescorer('<%=match.getScorersA().players()[u].getName()%>')"></td> </b></tr><%}%></table></td>
          <td><span class="nlp"><%for(int u=0;u<match.getScorersB().players().length;u++){%><%=match.getScorersB().players()[u].getName()%>(<%=match.getScorersB().players()[u].getGoals()%>)<br/><%}%></span></td>
        
        <%}else{%>
        <td><span class="nlp"><%for(int u=0;u<match.getScorersA().players().length;u++){%><%=match.getScorersA().players()[u].getName()%>(<%=match.getScorersA().players()[u].getGoals()%>)<br/><%}%></span></td>
        <td ><table width="250px"><%for(int u=0;u<match.getScorersB().players().length;u++){%><tr><td><b><input type="hidden" value="<%=match.getScorersB().players()[u].getName()%>" name="scorerB<%=u%>" /><%=match.getScorersB().players()[u].getName()%></b></td><td><b><input type="text" size="2" name="scoredgoalsB<%=u%>" value="<%=match.getScorersB().players()[u].getGoals()%>" maxlength=2/></td> <td>- Delete<input type="checkbox" onClick="javascript:deletescorer('<%=match.getScorersB().players()[u].getName()%>')"></td> </b></tr><%}%></table></td>
          
        <%}%>
    </tr>
    
   
    
    <tr></tr>
    </table> 
    
        <br/>
              <br/>
          <table>
          <tr><td><input type="text" id="addscorer" name="newsc0rer" onFocus="javascript:highlight(this.value)" onkeyup="javascript:autocomplete(event)"/> </td><td><input type="text" size="2" name="newsc0rergoals" /> </td><td><a href="javascript:confirmScorer(document.resultform.newsc0rer.value,document.resultform.newsc0rergoals.value)"><b>Confirm scorer</b></a></td></tr>
          
  </table>
   <br/>
  <span id="existingscorertable"><u><strong>Scorers</strong></u><br/></span>
  <br/>
  Add a Match Report: <input type="checkbox" name="addreport" value="addreport">
  <br/>
<br/>
    <input type="text" name="author" value="<%if(report!=null){%><%=report.getAuthor()%><%}%>"/> <input type="text" name="title" value="<%if(report!=null){%><%=report.getTitle()%><%}%>" size="45"/>
    <br/>
      <textarea id="textarea1" name="report" style="height: 400px; width: 450px;"><%if(report!=null){%><%=report.getReport()%><%}%></textarea>
      <script language="javascript1.2">
        generate_wysiwyg('textarea1');
      </script>
  
  
  <br/>
  <br/>
   <input class='leftbutton' type='submit' name='submit' value='Update' />
   <br/><br/>
    </div>
    </li>
   
</ul>
</form>

